<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        padding: 0;
        margin: 0;
      }
      .container p {
        cursor: pointer;
        margin: 10px;
        padding: 8px;
      }
      p.active {
        background: #ccc;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Sit, corporis!</p>
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
      <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Nisi minima dignissimos adipisci!</p>
      <p>Lorem ipsum dolor sit amet consectetur.</p>
    </div>

    <script>
      const ps = document.querySelectorAll('p')
      const clickChange = ev => {
        const id = parseInt(ev.target.id) + 1
        ev.target.setAttribute('id', id)
        if (id % 2 === 0) ev.target.classList.remove('active')
        if (id % 2 === 1) ev.target.classList.add('active')
      }
      for (let i = 0; i < ps.length; i++) {
        ps[i].setAttribute('id', 0)
        ps[i].addEventListener('click', clickChange)
      }
    </script>
  </body>
</html>
